Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix classification report if dataset has no labels #3375

Merged
merged 6 commits into from
Dec 5, 2023

Conversation

alanakbik
Copy link
Collaborator

If the test dataset has no labels, and the model makes no predictions, no evaluation numbers (precision/recall/F1) can be computed. This causes errors in cases such as this:

import flair
from flair.data import Corpus
from flair.datasets import ColumnCorpus, WNUT_17
from flair.embeddings import TransformerWordEmbeddings
from flair.models import SpanClassifier
from flair.trainers import ModelTrainer

flair.set_seed(123)

corpus: Corpus = WNUT_17().downsample(0.01)

label_dictionary = corpus.make_label_dictionary("ner", add_unk=True)

embeddings = TransformerWordEmbeddings(
    model="distilbert-base-uncased", layers="-1", subtoken_pooling="first", fine_tune=True, use_context=True
)

tagger = SpanClassifier(embeddings=embeddings, label_dictionary=label_dictionary)

trainer = ModelTrainer(tagger, corpus)

trainer.fine_tune(
    "./results/",
    max_epochs=1,
)

This PR slightly refactors the evaluate() code in the DefaultClassifier such that the error handling for this case becomes more explicit. This also fixes the above error.

@alanakbik alanakbik changed the title Fix classification report Fix classification report if dataset has no labels Nov 12, 2023
flair/nn/model.py Outdated Show resolved Hide resolved
@alanakbik alanakbik merged commit 28c9a83 into master Dec 5, 2023
1 check passed
@alanakbik alanakbik deleted the fix_classification_report branch December 5, 2023 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants